package com.jlect.swebing.ui.client;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * Act as multi cast for the action events
 * @author Sergey Kozmin
 * @since 15.11.2007 11:35:36
 */
public class ActionListenerCollection extends ArrayList {
    private ClickActionEvent clickEvent;
    private TextActionEvent textEvent;

    public void actionPerformed(ActionEvent event) {
        for (Iterator iterator = iterator(); iterator.hasNext();) {
            ActionListener listener = (ActionListener) iterator.next();
            listener.actionPerformed(event);
        }
    }

    public void clickActionPerformed(MouseEvent evt) {
        if(clickEvent == null) {
            clickEvent = new ClickActionEvent(evt);
        } else {
            clickEvent.setInitialEvent(evt);
        }
        actionPerformed(clickEvent);
    }

    public void textActionPerformed(GComponent component) {
        if(textEvent == null) {
            textEvent = new TextActionEvent(component);
        } else {
            textEvent.setSource(component);
        }
        actionPerformed(textEvent);
    }
}
